## 这个软件的主要功能是计算达到目标体重需要花费的时间
## 
import openpyxl
import matplotlib.pyplot as plt
class lose_weight():
    def __init__(self) :
        self.name = "毛逸鹏" 
        self.age=26
        self.weight_now=80.1
        self.weight_target=77
        self.stature = 1.78
        self.sex = 1
    def computer_days(self,workout_cal,eat_cal):
        self.calc_BMI()
        base = self.calc_RMR()
        target = self.weight_now-self.weight_target
        workout_day = (target*10000)/(workout_cal+base-eat_cal)
        print(workout_day)
    def computer_target(self,workout_day,eat_cal):
        self.calc_BMI()
        base = self.calc_RMR()
        target = self.weight_now-self.weight_target
        workout_cal = (target*10000)/workout_day-(base-eat_cal)
        print("额外消耗的卡路里"+str(workout_cal)+"kcal")
        return workout_cal
    def computer_run(self,workout_day,eat_cal):
        workout = self.computer_target(workout_day,eat_cal)
        run_cal = (self.weight_now+self.weight_target)/2 * 0.98
        print("需要跑的距离"+str(workout/run_cal)+"km")
    def calc_BMI(self):
        BMI = self.weight_now/(self.stature**2)
        if BMI <=18.4:
            print("消瘦")
        elif BMI>=18.4 and BMI<=23.9:
            print("正常")
        elif BMI>=24 and BMI<=27.9:
            print("超重")
        else:
            print("肥胖")
        print("BMI指数"+str(BMI))
        return BMI
    def calc_RMR(self):
        RMR = 0
        if self.sex:
            RMR = 67+13.73*self.weight_now+5*self.stature*100-6.9*self.age
            print("基础代谢率"+str(RMR))
        else:
            RMR = 661+9.6*self.weight_now+1.72*self.stature*100-4.7*self.age
            print(RMR)
        return RMR
    def read_execl(self):
        wb = openpyxl.load_workbook('运动记录.xlsx')
        sh = wb["Sheet1"]
        date = []
        weight = []
        Calorie = []
        num_row = sh.max_row
        for i in range(2,num_row):
            ce = sh.cell(row = i,column = 1)
            date.append(ce.value)
        for i in range(2,num_row):
            ce = sh.cell(row = i,column = 2)
            weight.append(ce.value)    
        for i in range(2,num_row):
            ce = sh.cell(row = i,column = 3)
            Calorie.append(ce.value)   
        plt.subplot(2,1,1)     
        plt.plot(date,weight)
        plt.subplot(2,1,2)
        plt.plot(date,Calorie)
        plt.show()    
if __name__=="__main__":
    workout = lose_weight()
    # print("目标体重"+str(workout.weight_target))
    # day = 20
    # eat = 1400
    # print("计划时间"+str(day))
    # workout.computer_run(20,1400)
    workout.read_execl()
